package cn.zhj.base.mvp.ui.base

import android.view.Gravity
import android.view.ViewGroup
import android.widget.TextView
import cn.zhj.mvpart.mvp.BaseActivity
import cn.zhj.mvpart.mvp.IPresenter
import cn.zhj.base.R
import cn.zhj.base.mvp.ui.view.CommonDialog

abstract class BaseModuledActivity<P : IPresenter> : BaseActivity<P>() {
    private var dialogLoading: CommonDialog? = null

    override fun showLoading() {
        if (dialogLoading != null && dialogLoading!!.isShowing()) {
            dialogLoading!!.dismiss()
        }
        dialogLoading = CommonDialog(
            this,
            R.layout.dialog_loading,
            Gravity.CENTER
            ,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        )
        dialogLoading!!.setCancelable(true)
        dialogLoading!!.show()
    }

    open fun showLoading(msg: String?) {
        if (dialogLoading != null && dialogLoading!!.isShowing()) {
            dialogLoading!!.dismiss()
        }
        dialogLoading = CommonDialog(
            this,
            R.layout.dialog_loading,
            Gravity.CENTER
            ,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        )
        val textView: TextView = dialogLoading!!.findViewById(R.id.tip)
        textView.text = msg
        dialogLoading!!.setCancelable(true)
        dialogLoading!!.show()
    }

    override fun hideLoading() {
        if (dialogLoading != null && dialogLoading!!.isShowing()) {
            dialogLoading!!.dismiss()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        if (dialogLoading != null && dialogLoading!!.isShowing()) {
            dialogLoading!!.dismiss()
        }
    }

    override fun showMessage(message: String) {

    }
}